package com.lakeworks.web.controller.core;

import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.core.page.TableDataInfo;
import com.lakeworks.domain.status.StaProduct;
import com.lakeworks.service.IStaProductService;
import com.lakeworks.service.IThirdChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 产品状态Controller
 *
 * @author lake
 * @date 2023-02-23
 */
@RestController
@RequestMapping("/post/product")
public class StaProductController extends BaseController {
    @Autowired
    private IStaProductService staProductService;

    @Autowired
    private IThirdChannelService thirdChannelService;

    /**
     * 查询产品状态列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StaProduct staProduct) {
        startPage();
        List<StaProduct> list = staProductService.selectStaProductList(staProduct);
        return getDataTable(list);
    }

//    /**
//     * 导出产品状态列表
//     */
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, StaProduct staProduct)
//    {
//        List<StaProduct> list = staProductService.selectStaProductList(staProduct);
//        ExcelUtil<StaProduct> util = new ExcelUtil<StaProduct>(StaProduct.class);
//        util.exportExcel(response, list, "产品状态数据");
//    }

    /**
     * 获取产品状态详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(staProductService.selectStaProductById(id));
    }

    /**
     * 新增产品状态
     */
    @PostMapping
    public AjaxResult add(@RequestBody StaProduct staProduct) {
        return toAjax(staProductService.insertStaProduct(staProduct));
    }

    /**
     * 修改产品状态
     */
    @PutMapping
    public AjaxResult edit(@RequestBody StaProduct staProduct) {
        return toAjax(staProductService.updateStaProduct(staProduct));
    }

    /**
     * 删除产品状态
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(staProductService.deleteStaProductByIds(ids));
    }

    @GetMapping("/{barcode}/flows")
    public ResponseEntity statusByBarcode(@PathVariable String barcode) {
        return thirdChannelService.statusByBarcode(barcode);
    }
}
